package com.gprinter.sample;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;

public class BitmapManager {
    private int pageOff = 10;
    private int coHeight = 0;
    private Bitmap bitmap;
    private Paint mPaint;
    private Canvas mCanvas;
    private int viewWidth;
    private int viewHeigth;
    float cl1Width = 0;
    private static BitmapManager manager;
    public static BitmapManager manager(){
        if(manager==null){
            synchronized (BitmapManager.class){
                if(manager==null){
                    manager = new BitmapManager();
                }
            }
        }
        return manager;
    }

    private void init(int width,int height){
        this.viewWidth = width;
        this.viewHeigth = height;

        mPaint = new Paint();
        mPaint.setAntiAlias(true);
        mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
        mPaint.setColor(Color.BLACK);
        mPaint.setStrokeWidth(3);
        bitmap = Bitmap.createBitmap(width,height, Bitmap.Config.RGB_565);
        mCanvas= new Canvas(bitmap);
        coHeight = (height-pageOff*2 - 3*6)/5;
    }




    public Bitmap drawQrBitmap(String qrMsg,int viewWidth,int viewHeigth,int count,int index
            ,String orderNum,String name,String typt,String addr,int kuai){
        init(viewWidth,viewHeigth);
        Bitmap qrbit = QRCodeUtil.createQRImage(qrMsg,180,180);
        float qrWidth = qrbit==null?0: qrbit.getWidth()+20;
        float qrHeight = qrbit==null?0: qrbit.getHeight();
        mCanvas.drawColor(Color.WHITE);

        mCanvas.drawBitmap(qrbit,viewWidth-qrWidth+8,pageOff+3+coHeight-qrHeight/2,mPaint);
        qrbit.recycle();
        mCanvas.drawLine(pageOff,pageOff,viewWidth-pageOff,pageOff,mPaint);
        mCanvas.drawLine(pageOff,pageOff,pageOff,viewHeigth-pageOff,mPaint);
        mCanvas.drawLine(pageOff,viewHeigth-pageOff,viewWidth-pageOff,viewHeigth-pageOff,mPaint);
        mCanvas.drawLine(viewWidth-pageOff,pageOff,viewWidth-pageOff,viewHeigth-pageOff,mPaint);

        mCanvas.drawLine(pageOff,coHeight+pageOff+3,viewWidth-qrWidth,coHeight+pageOff+3,mPaint);
        mCanvas.drawLine(pageOff,coHeight*2+pageOff+3*2,viewWidth-pageOff,coHeight*2+pageOff+3*2,mPaint);
        mCanvas.drawLine(pageOff,coHeight*3+pageOff+3*3,viewWidth-pageOff,coHeight*3+pageOff+3*3,mPaint);
        mCanvas.drawLine(pageOff,coHeight*4+pageOff+3*4,viewWidth-pageOff,coHeight*4+pageOff+3*4,mPaint);

        mPaint.setTextSize(20);
        float width = mPaint.measureText("产品型号");
        mCanvas.drawLine(pageOff+3*2+width+4+20,pageOff,pageOff+3*2+width+4+20,viewHeigth-pageOff,mPaint);
        mPaint.setStrokeWidth(1);

        //单号
        float clumWidth = width + 4;
        cl1Width = clumWidth;

        float numWidth = mPaint.measureText("单号");

        float startX = clumWidth - numWidth+6+2;
        float startY = coHeight/2 + numWidth/4+pageOff;
        addText2("单号",35,startX-30,startY);

        //联系人
        String text = "联系人";
        float lxWidth  = mPaint.measureText(text);

        startX = clumWidth - lxWidth+6+2;
        startY = coHeight*3/2+pageOff+lxWidth/3/2+3;
        addText2(text,35,startX+20,startY);

        //产品型号
        text = "型号";
        lxWidth  = mPaint.measureText(text);

        startX = clumWidth - lxWidth+6+2;
        startY = coHeight*2+coHeight/2+pageOff+lxWidth/4/2+3*2+10;
        addText2(text,35,startX-5,startY);

        //终端地址
        text = "地址";
        lxWidth  = mPaint.measureText(text);

        startX = clumWidth - lxWidth+6+2;
        startY = coHeight*3+coHeight/2+pageOff+lxWidth/4/2+3*3+10;
        addText2(text,35,startX,startY);

        //产品数量
        text = "数量";
        lxWidth  = mPaint.measureText(text);

        startX = clumWidth - lxWidth+6+2;
        startY = coHeight*4+coHeight/2+pageOff+lxWidth/4/2+3*4+10;
        addText2(text,35,startX,startY);

        numWidth = addNum(orderNum);
        mPaint.setStrokeWidth(3);

        text = "物流";
        mPaint.setStrokeWidth(1);
        mPaint.setTextSize(20);
        float textWidth = mPaint.measureText(text);

        float wlWidth = clumWidth+3*2+ numWidth+textWidth+3*2+3*2;
        mPaint.setStrokeWidth(3);
        mCanvas.drawLine(viewWidth-qrWidth,pageOff,viewWidth-qrWidth,pageOff+coHeight*2+3*2,mPaint);

        float bWidth = wlWidth - (pageOff+3*2+width+4);
        mPaint.setStrokeWidth(1);
        text = name;
        mPaint.setTextSize(45);
        float widthj = mPaint.measureText(text);
        mCanvas.drawText(text,pageOff+3*2+width+4+bWidth/2-widthj/2-80,coHeight+pageOff+coHeight/2+widthj/3/2+15,mPaint);

        text = typt;
        mPaint.setTextSize(45);
        float widthe = mPaint.measureText("奥运");
        mCanvas.drawText(text,pageOff+3*2+width+4+50,coHeight*2+pageOff+coHeight/2+widthe/2/2+3,mPaint);

        text = addr;
        mCanvas.drawText(text,pageOff+3*2+width+4+50,coHeight*3+pageOff+coHeight/2+widthe/2/2+3*2,mPaint);

        text = String.format("共%d 块，共 %d 包，第 %d 包",kuai,count,index);
        mCanvas.drawText(text,pageOff+3*2+width+4+30,coHeight*4+pageOff+coHeight/2+widthe/2/2+3*3,mPaint);
        Matrix matrix = new Matrix();
        matrix.postRotate(90);
        bitmap = Bitmap.createBitmap(bitmap,0,0,bitmap.getWidth(),bitmap.getHeight(),matrix,true);
        return bitmap;
    }














    public Bitmap getBitmap(int width,int height,
                            String name,String num,String wuliu,String type,String addr,String other,int count,int index,int kuai) {
        init(width,height);
        drawbg1(name, num, wuliu, type, addr, other, count, index,kuai);
        return bitmap;
    }

    public Bitmap getBitmap2(int width,int height
      ,String name,int count,int index,String wuliu,String type,String azdizhi,String addr,String orderNum ,int kuai) {
        init(width,height);
        draw2(name, count, index, wuliu, type, azdizhi, addr,orderNum,  kuai);
        return bitmap;
    }

    public void draw2(String name,int count,int index,String wuliu,String type,String azdizhi,String addr,String orderNum,int kuai){
        mCanvas.drawColor(Color.WHITE);
        mPaint.setStrokeWidth(3);
        mCanvas.drawLine(pageOff,pageOff,viewWidth-pageOff,pageOff,mPaint);
        mCanvas.drawLine(pageOff,pageOff,pageOff,viewHeigth-pageOff,mPaint);
        mCanvas.drawLine(pageOff,viewHeigth-pageOff,viewWidth-pageOff,viewHeigth-pageOff,mPaint);
        mCanvas.drawLine(viewWidth-pageOff,pageOff,viewWidth-pageOff,viewHeigth-pageOff,mPaint);

        mPaint.setTextSize(90);
        pageOff=30;
        float offsetH = 0;
        float width = mPaint.measureText("小");
        mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
        mCanvas.drawText("小",pageOff+20,pageOff+width,mPaint);

        mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
        mCanvas.drawText("心",pageOff+20,pageOff+width*2+20,mPaint);

        mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
        mCanvas.drawText("易",pageOff+20,pageOff+width*3+20*2,mPaint);

        mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
        mCanvas.drawText("碎",pageOff+20,pageOff+width*4+20*3,mPaint);

        offsetH = pageOff+20;
        float off = viewHeigth/8;

        String num = orderNum;
        mPaint.setTextSize(35);
        mPaint.setStrokeWidth(1);
        float numWidth = mPaint.measureText(num) ;
        mCanvas.drawText(num,viewWidth-numWidth-60,offsetH+20,mPaint);

        float offWidth = pageOff+20+150;
        numWidth = mPaint.measureText("产品数量");

        float dis = 55;
        String text = "经销商";
        mCanvas.drawText(text,offWidth+numWidth-mPaint.measureText(text),off+dis+10,mPaint);
        mPaint.setStrokeWidth(3);
        mCanvas.drawLine(offWidth+numWidth,off+dis+20,viewWidth-pageOff,off+dis+20,mPaint);

        mPaint.setStrokeWidth(1);
        text = "地址";
        mCanvas.drawText(text,offWidth+numWidth-mPaint.measureText(text),off+dis*2+10,mPaint);
        mPaint.setStrokeWidth(3);
        mCanvas.drawLine(offWidth+numWidth,off+dis*2+20,viewWidth-pageOff,off+dis*2+20,mPaint);

        mPaint.setStrokeWidth(1);
        text = "安装地址";
        mCanvas.drawText(text,offWidth+numWidth-mPaint.measureText(text),off+dis*3+10,mPaint);
        mPaint.setStrokeWidth(3);
        mCanvas.drawLine(offWidth+numWidth,off+dis*3+20,viewWidth-pageOff,off+dis*3+20,mPaint);

        mPaint.setStrokeWidth(1);
        text = "产品类型";
        mCanvas.drawText(text,offWidth+numWidth-mPaint.measureText(text),off+dis*4+10,mPaint);
        mPaint.setStrokeWidth(3);
        mCanvas.drawLine(offWidth+numWidth,off+dis*4+20,viewWidth-pageOff,off+dis*4+20,mPaint);

        mPaint.setStrokeWidth(1);
        text = "建议物流";
        mCanvas.drawText(text,offWidth+numWidth-mPaint.measureText(text),off+dis*5+10,mPaint);
        mPaint.setStrokeWidth(3);
        mCanvas.drawLine(offWidth+numWidth,off+dis*5+20,viewWidth-pageOff,off+dis*5+20,mPaint);

        mPaint.setStrokeWidth(1);
        text = "数量";
        mCanvas.drawText(text,offWidth+numWidth-mPaint.measureText(text),off+dis*6+10,mPaint);
        mPaint.setStrokeWidth(3);
        mCanvas.drawLine(offWidth+numWidth,off+dis*6+20,viewWidth-pageOff,off+dis*6+20,mPaint);

        mPaint.setStrokeWidth(1);
        float lineWidth = viewWidth-5 - offWidth-numWidth;
        String jinxs = name;
        mPaint.setTextSize(50);
        float xWidth = mPaint.measureText(jinxs);
        float startX = offWidth+numWidth + lineWidth/2-xWidth/2;
        float startY = off+dis+20-xWidth/3/2;
        mCanvas.drawText(jinxs,startX,startY,mPaint);

        mPaint.setTextSize(30);
        xWidth = mPaint.measureText(jinxs);
        startX = offWidth+numWidth + lineWidth/2-xWidth/2;
        startY = off+dis*2+20-xWidth/addr.length()/2;
        mCanvas.drawText(addr,startX,startY,mPaint);

        float fontHeight = xWidth/addr.length()/2;

        String anzAddr = azdizhi;
        xWidth = mPaint.measureText(anzAddr);
        startX = offWidth+numWidth + lineWidth/2-xWidth/2;
        startY = off+dis*3+20-fontHeight;
        mCanvas.drawText(anzAddr,startX,startY,mPaint);

        xWidth = mPaint.measureText(type);
        startX = offWidth+numWidth + lineWidth/2-xWidth/2;
        startY = off+dis*4+20-fontHeight;
        mCanvas.drawText(type,startX,startY,mPaint);

        xWidth = mPaint.measureText(wuliu);
        startX = offWidth+numWidth + lineWidth/2-xWidth/2;
        startY = off+dis*5+20-fontHeight;
        mCanvas.drawText(wuliu,startX,startY,mPaint);

        String countStr = String.format("共%d块，共%d包，第%d包",kuai,count,index);
        xWidth = mPaint.measureText(countStr);
        startX = offWidth+numWidth + lineWidth/2-xWidth/2;
        startY = off+dis*6+20-fontHeight;
        mCanvas.drawText(countStr,startX,startY,mPaint);

        Matrix matrix = new Matrix();
        matrix.postRotate(90);
        bitmap = Bitmap.createBitmap(bitmap,0,0,bitmap.getWidth(),bitmap.getHeight(),matrix,true);
    }


    public Bitmap getBitmap4(int viewWidth, int height, String name, String num, String wuliu, String type, String addr, String other, int count, int index
            , String detail) {
        init(viewWidth,height);
        draw4(viewWidth, height, name, num, wuliu, type, addr, other, count, index, detail);
        return bitmap;
    }

    private void draw4(int viewWidth, int height, String name, String num, String wuliu, String type, String addr, String other, int count, int index
            , String detail){

        coHeight = (height-pageOff*2 - 3*6)/7;

        mCanvas.drawColor(Color.WHITE);
        mCanvas.drawLine(pageOff,pageOff,viewWidth-pageOff,pageOff,mPaint);
        mCanvas.drawLine(pageOff,pageOff,pageOff,viewHeigth-pageOff,mPaint);
        mCanvas.drawLine(pageOff,viewHeigth-pageOff,viewWidth-pageOff,viewHeigth-pageOff,mPaint);
        mCanvas.drawLine(viewWidth-pageOff,pageOff,viewWidth-pageOff,viewHeigth-pageOff,mPaint);

        mCanvas.drawLine(pageOff,coHeight+pageOff+3,viewWidth-pageOff,coHeight+pageOff+3,mPaint);
        mCanvas.drawLine(pageOff,coHeight*2+pageOff+3*2,viewWidth-pageOff,coHeight*2+pageOff+3*2,mPaint);
        mCanvas.drawLine(pageOff,coHeight*3+pageOff+3*3,viewWidth-pageOff,coHeight*3+pageOff+3*3,mPaint);
        mCanvas.drawLine(pageOff,coHeight*4+pageOff+3*4,viewWidth-pageOff,coHeight*4+pageOff+3*4,mPaint);
        mCanvas.drawLine(pageOff,coHeight*5+pageOff+3*5,viewWidth-pageOff,coHeight*5+pageOff+3*5,mPaint);

        mPaint.setTextSize(25);
        float width = mPaint.measureText("型号");
        mCanvas.drawLine(pageOff+3*2+width+4,pageOff,pageOff+3*2+width+4,viewHeigth-pageOff,mPaint);
        mPaint.setStrokeWidth(1);

        //单号
        float clumWidth = width + 4;
        cl1Width = clumWidth;

        float numWidth = mPaint.measureText("单号");

        float startX = clumWidth - numWidth+6+2;
        float startY = coHeight/2 + numWidth/4+pageOff;
        addText("单号",20,startX,startY);


        //联系人
        String text = "客户";
        float lxWidth  = mPaint.measureText(text);

        startX = clumWidth - lxWidth+6+2;
        startY = coHeight*3/2+pageOff+lxWidth/3/2+3;
        addText(text,20,startX,startY);

        //产品型号
        text = "型号";
        lxWidth  = mPaint.measureText(text);

        startX = clumWidth - lxWidth+6+2;
        startY = coHeight*2+coHeight/2+pageOff+lxWidth/4/2+3*2;
        addText(text,20,startX,startY);

        //终端地址
        text = "地址";
        lxWidth  = mPaint.measureText(text);

        startX = clumWidth - lxWidth+6+2;
        startY = coHeight*3+coHeight/2+pageOff+lxWidth/4/2+3*3;
        addText(text,20,startX,startY);

        //产品数量
        text = "数量";
        lxWidth  = mPaint.measureText(text);

        startX = clumWidth - lxWidth+6+2;
        startY = coHeight*4+coHeight/2+pageOff+lxWidth/4/2+3*4;
        addText(text,20,startX,startY);

        text = "包内明细";
        lxWidth  = mPaint.measureText(text);

        startX = clumWidth - lxWidth+6+2;
        startY = coHeight*5+coHeight+pageOff+lxWidth/4/2+3*5;
        addText(text,20,startX,startY);

        numWidth = addNum(num);
        mPaint.setStrokeWidth(3);
        mCanvas.drawLine(clumWidth+3*2+ numWidth,pageOff,clumWidth+3*2+ numWidth,pageOff+coHeight,mPaint);

        text = "单号";
        mPaint.setStrokeWidth(1);
        mPaint.setTextSize(20);
        float textWidth = mPaint.measureText(text);
        mCanvas.drawText(text,clumWidth+3*2+ numWidth+3*2,pageOff+coHeight/2+textWidth/4-3,mPaint);

        float wlWidth = clumWidth+3*2+ numWidth+textWidth+3*2+3*2;
        mPaint.setStrokeWidth(3);
        mCanvas.drawLine(wlWidth,pageOff,wlWidth,pageOff+coHeight*2+3*2,mPaint);

        text = wuliu;
        mPaint.setStrokeWidth(1);
        mPaint.setTextSize(30);
        numWidth = mPaint.measureText(text);
        mCanvas.drawText(text,wlWidth+10,pageOff+coHeight/2+numWidth/4/2-3,mPaint);

        float bWidth = wlWidth - (pageOff+3*2+width+4);

        text = name;
        mPaint.setTextSize(45);
        float widthj = mPaint.measureText(text);
        mCanvas.drawText(text,pageOff+3*2+width+4+bWidth/2-widthj/2,coHeight+pageOff+coHeight/2+widthj/3/2,mPaint);

        text = other;
        mPaint.setTextSize(30);
        float widthx = mPaint.measureText(text);
        mCanvas.drawText(text,wlWidth+10,coHeight+pageOff+coHeight/2+widthx/3/2,mPaint);

        text = type;
        mPaint.setTextSize(30);
        float widthe = mPaint.measureText("奥运");
        mCanvas.drawText(text,pageOff+3*2+width+4+10,coHeight*2+pageOff+coHeight/2+widthe/2/2+3,mPaint);

        text = addr;
        mCanvas.drawText(text,pageOff+3*2+width+4+10,coHeight*3+pageOff+coHeight/2+widthe/2/2+3*2,mPaint);

        text = String.format("共 %d 包，第 %d 包", count,index);
        mCanvas.drawText(text,pageOff+3*2+width+4+10,coHeight*4+pageOff+coHeight/2+widthe/2/2+3*3,mPaint);

        mPaint.setTextSize(25);
        float textOff = 2;
        float textPageOff = 2;
        float msgWidth = mPaint.measureText(detail);
        float oneWidth = msgWidth/detail.length();
        float maxWidth = viewWidth-clumWidth- pageOff*2-3*3;
        float maxHeight = coHeight*2;

        int sizeLine = (int) ((maxWidth - textPageOff*2)/oneWidth);
        int cLast = detail.length()%sizeLine;
        int cCount = cLast==0?detail.length()/sizeLine:(detail.length()/sizeLine+1);

        float sX = clumWidth+pageOff+3*2+textPageOff*2;
        float sY = 0;
        float hOff = coHeight*5+pageOff+3*6+oneWidth/2;
        for(int i=0;i<cCount;i++){
            sY =  hOff+(2*i+1)*oneWidth/2+textPageOff*(2*i+1);
            if(i==cCount-1){
                mCanvas.drawText(detail,i*sizeLine,(i)*sizeLine+cLast,sX,sY,mPaint);
            }else
                mCanvas.drawText(detail,i*sizeLine,(i+1)*sizeLine,sX,sY,mPaint);
        }

        Matrix matrix = new Matrix();
        matrix.postRotate(90);
        bitmap = Bitmap.createBitmap(bitmap,0,0,bitmap.getWidth(),bitmap.getHeight(),matrix,true);
    }









    private void drawbg1(String name,String num,String wuliu,String type,String addr,String other,int count,int index,int kuai){
        mCanvas.drawColor(Color.WHITE);
        mCanvas.drawLine(pageOff,pageOff,viewWidth-pageOff,pageOff,mPaint);
        mCanvas.drawLine(pageOff,pageOff,pageOff,viewHeigth-pageOff,mPaint);
        mCanvas.drawLine(pageOff,viewHeigth-pageOff,viewWidth-pageOff,viewHeigth-pageOff,mPaint);
        mCanvas.drawLine(viewWidth-pageOff,pageOff,viewWidth-pageOff,viewHeigth-pageOff,mPaint);

        mCanvas.drawLine(pageOff,coHeight+pageOff+3,viewWidth-pageOff,coHeight+pageOff+3,mPaint);
        mCanvas.drawLine(pageOff,coHeight*2+pageOff+3*2,viewWidth-pageOff,coHeight*2+pageOff+3*2,mPaint);
        mCanvas.drawLine(pageOff,coHeight*3+pageOff+3*3,viewWidth-pageOff,coHeight*3+pageOff+3*3,mPaint);
        mCanvas.drawLine(pageOff,coHeight*4+pageOff+3*4,viewWidth-pageOff,coHeight*4+pageOff+3*4,mPaint);

        mPaint.setTextSize(35);
        float width = mPaint.measureText("型号");
        mCanvas.drawLine(pageOff+3*2+width+4,pageOff,pageOff+3*2+width+4,viewHeigth-pageOff,mPaint);
        mPaint.setStrokeWidth(1);

        //单号
        float clumWidth = width + 4;
        cl1Width = clumWidth;

        float numWidth = mPaint.measureText("单号");

        float startX = clumWidth - numWidth+6+2;
        float startY = coHeight/2 + numWidth/4+pageOff;
        addText("单号",20,startX,startY);


        //联系人
        String text = "客户";
        float lxWidth  = mPaint.measureText(text);

        startX = clumWidth - lxWidth+6+2;
        startY = coHeight*3/2+pageOff+lxWidth/3/2+3;
        addText(text,20,startX,startY);

        //产品型号
        text = "型号";
        lxWidth  = mPaint.measureText(text);

        startX = clumWidth - lxWidth+6+2;
        startY = coHeight*2+coHeight/2+pageOff+lxWidth/4/2+3*2;
        addText(text,20,startX,startY);

        //终端地址
        text = "地址";
        lxWidth  = mPaint.measureText(text);

        startX = clumWidth - lxWidth+6+2;
        startY = coHeight*3+coHeight/2+pageOff+lxWidth/4/2+3*3;
        addText(text,20,startX,startY);

        //产品数量
        text = "数量";
        lxWidth  = mPaint.measureText(text);

        startX = clumWidth - lxWidth+6+2;
        startY = coHeight*4+coHeight/2+pageOff+lxWidth/4/2+3*4;
        addText(text,20,startX,startY);

        numWidth = addNum(num);
        mPaint.setStrokeWidth(3);
        mCanvas.drawLine(clumWidth+3*2+ numWidth+70,pageOff,clumWidth+3*2+ numWidth+70,pageOff+coHeight,mPaint);

        text = "物流";
        mPaint.setStrokeWidth(1);
        mPaint.setTextSize(35);
        float textWidth = mPaint.measureText(text);
        mCanvas.drawText(text,clumWidth+3*2+ numWidth+3*2+70,pageOff+coHeight/2+textWidth/4-3,mPaint);

        float wlWidth = clumWidth+3*2+ numWidth+textWidth+3*2+3*2;
        mPaint.setStrokeWidth(3);
        mCanvas.drawLine(wlWidth+70,pageOff,wlWidth+70,pageOff+coHeight*2+3*2,mPaint);

        text = wuliu;
        mPaint.setStrokeWidth(1);
        mPaint.setTextSize(40);
        numWidth = mPaint.measureText(text);
        mCanvas.drawText(text,wlWidth+80,pageOff+coHeight/2+numWidth/4/2-3+10,mPaint);

        float bWidth = wlWidth - (pageOff+3*2+width+4);

        text = name;
        mPaint.setTextSize(45);
        float widthj = mPaint.measureText(text);
        mCanvas.drawText(text,pageOff+3*2+width+4+bWidth/2-widthj/2,coHeight+pageOff+coHeight/2+widthj/3/2+10,mPaint);

        text = other;
        mPaint.setTextSize(40);
        float widthx = mPaint.measureText(text);
        mCanvas.drawText(text,wlWidth+80,coHeight+pageOff+coHeight/2+widthx/3/2+10,mPaint);

        text = type;
        mPaint.setTextSize(45);
        float widthe = mPaint.measureText("奥运");
        mCanvas.drawText(text,pageOff+3*2+width+4+10,coHeight*2+pageOff+coHeight/2+widthe/2/2+3,mPaint);

        text = addr;


        mCanvas.drawText(text,pageOff+3*2+width+4+10,coHeight*3+pageOff+coHeight/2+widthe/2/2+3*2,mPaint);

        text = String.format("共%d 块，共 %d 包，第 %d 包",kuai,count,index);
        mPaint.setTextSize(50);
        float widthk = mPaint.measureText("奥运");
        mCanvas.drawText(text,pageOff+3*2+width+4+10,coHeight*4+pageOff+coHeight/2+widthk/2/2+3*3,mPaint);
        Matrix matrix = new Matrix();
        matrix.postRotate(90);
        bitmap = Bitmap.createBitmap(bitmap,0,0,bitmap.getWidth(),bitmap.getHeight(),matrix,true);

    }

    public void recycle(){
        if(bitmap!=null){
            bitmap.recycle();
        }
    }
    private void addText(String text,int textSize,float startX,float startY){
        mPaint.setStrokeWidth(1);
        mPaint.setTextSize(35);
        mCanvas.drawText(text,startX+5,startY,mPaint);
    }
    private void addText2(String text,int textSize,float startX,float startY){
        mPaint.setStrokeWidth(1);
        mPaint.setTextSize(textSize);
        mCanvas.drawText(text,startX+5,startY,mPaint);
    }
    public float  addNum(String num){
        int size =35;
        float startX = 20;
        mPaint.setTextSize(size);
        float width = mPaint.measureText("00318100362") + 5*2;
        startX =cl1Width + pageOff+3*2+5*4+20;
        float startY = pageOff+3+coHeight/2+width/11/2;
        addText(num,size,startX,startY);
        return width+5*4;
    }


}
